﻿function characterObj(x, y, vx, vy, ax, ay, d, f) {
	this.x      = x || 0;
	this.y      = y || 0;
	this.vx     = vx || 0;
	this.vy     = vy || 0;
	this.ax     = ax || 0;
	this.ay     = ay || 0;
	this.d      = d || 0;
	this.f      = f || 0;		// friction

	this.spd = 1.0;//控制速度
	this.maxspd = 1.0;
	this.minspd = 0.5;

	this.diva = 0;// 控制心跳动
	this.alpha;

	this.bub = 0;//控制隔一段时间吐一个泡泡，即能量随时间流逝
	this.act = 0;//用来控制海葵的速度

}

characterObj.prototype.draw = function(angle) {
	this.act++;

	if (this.spd > this.minspd) {//随时间消耗能量
		this.spd -= 0.0001;
		this.bub++;
	}
	//以下控制心跳透明度
	var gama = this.spd / this.maxspd;
	this.alpha = Math.pow(gama,1.7) * Math.sin(this.diva);

	var freq = 2000*Math.pow(gama,2);//次方可以控制鱼心跳的速度对比
	this.diva += Math.PI* time/freq;//与freq成反比
	if(this.diva >= Math.PI){
		this.diva = 0;//防止大于π的时候颜色变黑
	}


	ctx.save();
	ctx.translate(this.x, this.y);
	ctx.rotate(angle);

	fishHeartBump(this.alpha);

	ctx.restore();

}